<?php
require("db_config.php");
require("blowfish.php");

if(isset($_POST["MessageBlock"]) && isset($_POST['myID'])){
$totalMacIds=0;
$curtime=$_SERVER['REQUEST_TIME'];

$con = mysql_connect($db_host,$db_user,$db_password);
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db($db_name, $con);
$result = mysql_query("SELECT id FROM software where software_key='".$_POST['myID']."';");
$row=mysql_fetch_array($result);
if($row != null && $row != "")
{
	$software_id=$row['id'];
	$rs=mysql_query("select vi from audit where software_id = ".$software_id." and action='TOKEN-IO:ACCESS' and timestamp between ".($curtime-600)." and ".$curtime." order by timestamp DESC");
	$row=mysql_fetch_array($rs);
	$vi=$row['vi'];
	$data=decryptString(hex2bin($_POST["MessageBlock"]),$vi);
	$message = json_decode(stripslashes($data));
}



$result2= mysql_query("SELECT * FROM software WHERE software_key = '".$_POST['myID']."' and registered = 0");
if($result2 != null && $result2 != "" && $software_id > 0){

	if(isset($message->{"osName"})){
		$osName=$message->{"osName"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('osName','".$osName."',".$software_id.")");
	}
	if(isset($message->{"osVersion"})){
		$osVersion=$message->{"osVersion"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('osVersion','".$osVersion."',".$software_id.")");
	}
	if(isset($message->{"osProductKey"})){
		$osProductKey=$message->{"osProductKey"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('osProductKey','".$osProductKey."',".$software_id.")");
	}
	if(isset($message->{"osDriveSerialNumber"})){
		$osDriveSerialNumber=$message->{"osDriveSerialNumber"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('osDriveSerialNumber','".$osDriveSerialNumber."',".$software_id.")");
	}
	if(isset($message->{"osOriginalInstallDate"})){
		$osOriginalInstallDate=$message->{"osOriginalInstallDate"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('osOriginalInstallDate','".$osOriginalInstallDate."',".$software_id.")");
	}
	if(isset($message->{"systemType"})){
		$systemType=$message->{"systemType"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('systemType','".$systemType."',".$software_id.")");
	}
	if(isset($message->{"physicalMemory"})){
		$physicalMemory=$message->{"physicalMemory"};
		mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('physicalMemory','".$physicalMemory."',".$software_id.")");
	}
	if(isset($message->{"macIdList"})){
		$macIdList=$message->{"macIdList"};
		$macIds=array();
		foreach($macIdList as $key => $value)
		{
			$macIds[$totalMacIds++] = $value;
			mysql_query("insert into t_anandsoftware_security_properties (`key`,`value`,`software_id`) values ('macId','".$value."',".$software_id.")");
		}
	}
}
// responce to request

echo "Parsed";
mysql_close($con);
}
?>